package com.colorlight.cloud.complete.entity.event;

import com.colorlight.cloud.complete.api.CompleteEntityEvent;
import com.colorlight.cloud.complete.entity.po.Location;
import com.colorlight.iot.proto.complete.event.CompleteEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;
/**
 * @author Demon
 * 主动上报位置信息，未存在或者位置信息未变化则无需主动上报
 * @date 29/5/2024  上午11:31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class LocationUpload implements CompleteEntityEvent {
	/**
	 * 主动上报位置信息，未存在或者位置信息未变化则无需主动上报
	 */
	private Location location;
	
	@Override
	public LocationUpload byteConvertObject(ByteString bytes) {
		
		CompleteEvent.LocationUpload locationUpload = null;
		try {
			locationUpload = CompleteEvent.LocationUpload.parseFrom(bytes);
		} catch (InvalidProtocolBufferException e) {
			log.error("", e);
		}
		Objects.requireNonNull(locationUpload);
		this.setLocation(new Location().formProto(locationUpload.getLocation()));
		return this;
	}
}
